package com.example.conference.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.example.conference.domain.User;
import com.example.conference.service.UserServiceImpl;
import com.example.conference.utils.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(originPatterns = "*",allowCredentials = "true")
public class LoginController {
    @Autowired
    UserServiceImpl userService;

    @RequestMapping("/login")
    public Result login(@RequestBody User u, HttpSession session){
        return userService.checklogin(u);
    }

    @RequestMapping("/info")
    public Result info(){
        return userService.info();
    }

    @RequestMapping("/logout")
    public Result logout(){
        StpUtil.logout();
        return Result.success();
    }
    // 全局异常拦截
    @ExceptionHandler
    public Result handlerException(Exception e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }
}

